//
//  OSXNotificationHandler
//  GitTFGUI
//
//  Created by Samuel Richard Magny on 2015-09-27.
//  Copyright © 2015 Samuel Richard Magny. All rights reserved.
//

import Cocoa

class OSXNotificationHandler: NSObject {

    private let _userNotificationCenter:NSUserNotificationCenter
    
    init(notificationCenter:TFSClientNotificationCenter)
    {
        _userNotificationCenter = NSUserNotificationCenter.defaultUserNotificationCenter()
        super.init()
        
        notificationCenter.subscribe(self, selector: "OnStopCommandReceived:", identifier: TFSClientNotification.NotificationType.CommandDidStoped)
    }
    
    func postCompletedCommandNotification(localizedCommandName:String, success:Bool)
    {
        let notification = NSUserNotification()
        
        if(success){
            notification.title = "Success"
        }
        else {
            notification.title = "Failed"
        }
        
        notification.informativeText = localizedCommandName.capitalizedString + " done"
        
        notification.deliveryDate = NSDate()
        
        _userNotificationCenter.scheduleNotification(notification)
    }
    
    dynamic func OnStopCommandReceived(notification: CommandStopedNotification){
        
       postCompletedCommandNotification(notification.commandType.description, success: notification.isSuccessful)
    }
    
    
}
